﻿using BYSJ.BLL;
using BYSJ.IBLL;
using BYSJ.Model;
using BYSJ.Web.Commmend;
using BYSJ.Web.Filters;
using BYSJ.Web.Models;
using BYSJ.Web.Models.File;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace BYSJ.Web.Controllers
{
    //当文件分类的id=1时 为通知
    //当文件分类的id=2时 为课件
    //当文件分类的id=3时 为实验指导
    //当文件分类的id=4时 为替他
    //当文件分类的id=>5时 为共享资源
    [AdminFilter]
    [ShenFen]
    public class FileController : Controller
    {
        IFileMangSetService fileServer = null;
        Commend com = new Commend();
        IvideojiluSetService videoJlu = null;
        public FileController()
        {
            fileServer = new FileMangSetService();
            videoJlu = new videojiluSetService();
        }
        [ShenFen]
        public ActionResult Index()
        {
            int totalCount = 0;
            //如果查询的结果为0则显示空视图
            var filedb1 = fileServer.LoadPageEntities(7, 1, out totalCount, u => u.FileIsdel == false&&u.Fileleibie==1, false, a => a.FilecreatTime).ToList();
            var filedb2 = fileServer.LoadPageEntities(7, 1, out totalCount, u => u.FileIsdel == false && u.Fileleibie == 2, false, a => a.FilecreatTime).ToList();
            var filedb3 = fileServer.LoadPageEntities(6, 1, out totalCount, u => u.FileIsdel == false && u.Fileleibie == 3, false, a => a.FilecreatTime).ToList();
            var filedb4 = fileServer.LoadPageEntities(6, 1, out totalCount, u => u.FileIsdel == false && u.Fileleibie == 4, false, a => a.FilecreatTime).ToList();
            FileDown file = com.FileConvert(filedb1, filedb2, filedb3, filedb4);
            return View(file);
        }

        public ActionResult Files(int Id)
        {
            var dbfiles = fileServer.LoadEntities(u=>u.Fileleibie==Id&&u.FileIsdel==false).ToList();
            FenLeiFile files = com.FilesConvert(dbfiles);
            return View(files);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id">视频id</param>
        /// <returns></returns>
        public string addVideoStudy(int id)
        {
            videojiluSet video = new videojiluSet();
            video.userid= Convert.ToInt32(Request.Cookies["cookiename"].Value);
            video.videoshouid = id;
            video.crettime = DateTime.Now;
           return videoJlu.Add(video).ToString();
          
        }
    }
}
